/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.base.web.customerdataconfig;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.base.entity.customerdataconfig.CustomerDataconfig;
import com.jeesite.modules.base.service.customerdataconfig.CustomerDataconfigService;
import com.jeesite.modules.sys.entity.User;
import com.jeesite.modules.sys.service.UserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 客户资料附件信息配置表Controller
 * @author LV
 * @version 2021-02-26
 */
@Controller
@RequestMapping(value = "${adminPath}/base/customerdataconfig/customerDataconfig")
public class CustomerDataconfigController extends BaseController {

	@Autowired
	private CustomerDataconfigService customerDataconfigService;
    @Autowired
    private UserService userService;

	/**
	 * 获取数据
	 */
	@ModelAttribute
	public CustomerDataconfig get(String dataconId, boolean isNewRecord) {
		return customerDataconfigService.get(dataconId, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("base:customerdataconfig:customerDataconfig:view")
	@RequestMapping(value = {"list", ""})
	public String list(CustomerDataconfig customerDataconfig, Model model) {
		model.addAttribute("customerDataconfig", customerDataconfig);
		return "modules/base/customerdataconfig/customerDataconfigList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("base:customerdataconfig:customerDataconfig:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<CustomerDataconfig> listData(CustomerDataconfig customerDataconfig, HttpServletRequest request, HttpServletResponse response) {
		customerDataconfig.setPage(new Page<>(request, response));
		Page<CustomerDataconfig> page = customerDataconfigService.findPage(customerDataconfig);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("base:customerdataconfig:customerDataconfig:view")
	@RequestMapping(value = "form")
	public String form(CustomerDataconfig customerDataconfig, Model model) {
        model.addAttribute("listUser", userService.findList(new User()));
		model.addAttribute("customerDataconfig", customerDataconfig);
		return "modules/base/customerdataconfig/customerDataconfigForm";
	}

	/**
	 * 查看表单详情
	 */
	@RequiresPermissions("base:customerdataconfig:customerDataconfig:view")
	@RequestMapping(value = "detail")
	public String detail(CustomerDataconfig customerDataconfig, Model model) {
        model.addAttribute("listUser", userService.findList(new User()));
		model.addAttribute("customerDataconfig", customerDataconfig);
		return "modules/base/customerdataconfig/customerDataconfigDetail";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("base:customerdataconfig:customerDataconfig:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated CustomerDataconfig customerDataconfig) {
		customerDataconfigService.save(customerDataconfig);
		return renderResult(Global.TRUE, text("保存客户资料附件信息配置表成功！"));
	}
	
	/**
	 * 停用数据
	 */
	@RequiresPermissions("base:customerdataconfig:customerDataconfig:edit")
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(CustomerDataconfig customerDataconfig) {
		customerDataconfig.setStatus(CustomerDataconfig.STATUS_DISABLE);
		customerDataconfigService.updateStatus(customerDataconfig);
		return renderResult(Global.TRUE, text("停用客户资料附件信息配置表成功"));
	}
	
	/**
	 * 启用数据
	 */
	@RequiresPermissions("base:customerdataconfig:customerDataconfig:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(CustomerDataconfig customerDataconfig) {
		customerDataconfig.setStatus(CustomerDataconfig.STATUS_NORMAL);
		customerDataconfigService.updateStatus(customerDataconfig);
		return renderResult(Global.TRUE, text("启用客户资料附件信息配置表成功"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("base:customerdataconfig:customerDataconfig:delete")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(CustomerDataconfig customerDataconfig) {
		customerDataconfigService.delete(customerDataconfig);
		return renderResult(Global.TRUE, text("删除客户资料附件信息配置表成功！"));
	}
	@RequestMapping(value = "getOneById")
	@ResponseBody
	public CustomerDataconfig getOneById(@RequestParam("dataconId") String dataconId) {
		return customerDataconfigService.get(dataconId);
	}
	
}